Skip to content

Conversation

@klabacher
Copy link

Summary
This PR suppresses EAI_NODATA from getaddrinfo() during connection checks, which occurs for domains that only have A (IPv4) or AAAA (IPv6) records and is expected behavior for single-stack domains.

Instead of throwing (and spamming logs), the code returns an empty socket so the connection attempt is skipped for the missing address family while still allowing checks to proceed normally.

Context / Motivation
WSL may log CheckConnection: getaddrinfo() failed for domains that are IPv4-only or IPv6-only, even though networking continues to work.

This change avoids unnecessary error logs while keeping real failures intact (non-EAI_NODATA errors still throw).

Changes
Handle status == EAI_NODATA right after getaddrinfo() and return an empty socket (unique_socket) instead of throwing.

Change is isolated to src/shared/inc/conncheckshared.h.

Issues
Fixes #13937 and #13820.

Validation steps performed
Ran simple validation on an isolated x64 environment:
Started WSL and verified general connectivity works as expected (internet OK).
Verified IPv6 did not trigger the previous error condition (no IPv6-related error observed).
Confirmed the log spam does not occur after the change for single-stack scenarios.

This change prevents getaddrinfo() from throwing an error when a domain
only has A records (IPv4) or AAAA records (IPv6), which is expected
behavior for single-stack domains.

Fixes microsoft#13937 and microsoft#13820
Copilot AI review requested due to automatic review settings January 2, 2026 16:14
@klabacher klabacher requested a review from a team as a code owner January 2, 2026 16:14
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes unnecessary error logging when WSL performs connection checks on domains that only support IPv4 or IPv6. The change suppresses the EAI_NODATA error returned by getaddrinfo() when a domain lacks records for the requested address family (e.g., IPv4-only domains have no AAAA records), which is expected behavior and should not generate error logs.

Key Changes:

  • Added special handling for EAI_NODATA error code after getaddrinfo() calls
  • Returns an empty socket instead of throwing an exception when EAI_NODATA is encountered
  • Connection check continues normally for the available address family while skipping the unavailable one

auto status = getaddrinfo(hostname, port, &hints, &servinfo);
if (status != 0)
{
if (status == EAI_NODATA)
Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EAI_NODATA is not portable across all platforms. On Windows, EAI_NODATA may not be defined in winsock2.h/ws2tcpip.h. On modern Linux systems, EAI_NODATA is deprecated and some systems use EAI_NONAME instead for the same scenario (no address records for the requested family).

Consider checking for both EAI_NODATA and EAI_NONAME, or wrapping this in platform-specific preprocessor checks to ensure the code compiles and works correctly on all target platforms.

Copilot uses AI. Check for mistakes.
throw std::runtime_error(std::format("CheckConnection: getaddrinfo() failed: {}", status));
}


Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank line added here. This appears to be unintentional formatting change that should be removed to maintain consistency with the existing code style.

Copilot uses AI. Check for mistakes.
@klabacher
Copy link
Author

@copilot open a new pull request to apply changes based on the comments in this thread

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unnecessary error: “getaddrinfo() failed: -5”

1 participant